<%--
  Created by IntelliJ IDEA.
  User: dzw
  Date: 2017/12/1
  Time: 13:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  String _id=request.getParameter("_");
  String jsessionid = session.getId();
%>

<div class="panel">

  <div class="panel-heading header" >
    <h3 class="panel-title" id="title">业务洽谈登记表</h3>
  </div>

  <div class="tab-content">
    <form id="form_businessTalk_input" class="form-horizontal">
      <input type="hidden" name="keyId" id="keyId" value="${businessTalk.id}"/>
      <input type="hidden" name="curDutyId" id="curDutyId" value=""/>

      <div class="form-group">
        <label class="col-md-2 control-label">
          客户名称
          <i class="fa fa-asterisk txt-color-red"></i>
        </label>
        <div class="col-md-6">
          <input disabled type="text" id="customerInfo" class="form-control" placeholder="请输入客户名称" value="${businessTalk.customerInfo.name}">
          <input type="hidden" id="customerInfoId" name="customerInfoId" class="form-control" value="${businessTalk.customerInfo.id}">
        </div>
      </div>

      <div class="form-group">
        <label class="col-md-2 control-label">开始时间<i class="fa fa-asterisk txt-color-red"></i></label>
        <div class="col-md-6">
          <input placeholder="请选择开始时间" id="startDate" name="startDate" class="form-control" type="text" value="<fmt:formatDate pattern="yyyy-MM-dd" value="${businessTalk.startDate}" />">
        </div>
      </div>

      <div class="form-group">
        <label class="col-md-2 control-label">结束时间<i class="fa fa-asterisk txt-color-red"></i></label>
        <div class="col-md-6">
          <input placeholder="请选择结束时间" id="endDate" name="endDate" class="form-control" type="text" value="<fmt:formatDate pattern="yyyy-MM-dd" value="${businessTalk.endDate}" />">
        </div>
      </div>

      <div class="form-group">
        <label class="col-md-2 control-label">洽谈主题<i class="fa fa-asterisk txt-color-red"></i></label>
        <div class="col-md-6">
          <input type="text" name="talkTopic" id="talkTopic" class="form-control" placeholder="请输入洽谈主题" value="${businessTalk.talkTopic}">
        </div>
      </div>

      <div class="form-group">
        <label class="col-md-2 control-label">洽谈方式<i class="fa fa-asterisk txt-color-red"></i></label>
        <div class="col-md-6">
          <div class="radio">
            <input type="radio" name="talkType" id="talkType1" value="上门拜访" class="magic-radio" <c:if test="${businessTalk.talkType=='上门拜访'}"> checked</c:if> >
            <label for="talkType1">上门拜访</label>
            <input type="radio" name="talkType" id="talkType2" value="邮件沟通" class="magic-radio" <c:if test="${businessTalk.talkType=='邮件沟通'}"> checked</c:if> >
            <label for="talkType2">邮件沟通</label>
            <input type="radio" name="talkType" id="talkType3" value="电话沟通" class="magic-radio" <c:if test="${businessTalk.talkType=='电话沟通'}"> checked</c:if> >
            <label for="talkType3">电话沟通</label>
          </div>
        </div>
      </div>

      <div class="form-group">
        <label class="col-md-2 control-label">洽谈地址<i class="fa fa-asterisk txt-color-red"></i></label>
        <div class="col-md-6">
          <input type="text" name="talkAddress" id="talkAddress" class="form-control" placeholder="请输入洽谈地址" value="${businessTalk.talkAddress}">
        </div>
      </div>

      <div class="form-group">
        <label class="col-md-2 control-label">洽谈对象<i class="fa fa-asterisk txt-color-red"></i></label>
        <div class="col-md-6">
          <input type="text" name="talkObject" id="talkObject" class="form-control" placeholder="请输入洽谈对象" value="${businessTalk.talkObject}">
        </div>
      </div>

      <div class="form-group">
        <label class="col-md-2 control-label">洽谈内容<i class="fa fa-asterisk txt-color-red"></i></label>
        <div class="col-md-6">
          <input type="text" name="talkContent" id="talkContent" class="form-control" placeholder="请输入洽谈内容" value="${businessTalk.talkContent}">
        </div>
      </div>

      <div class="form-group">
        <label class="col-md-2 control-label">洽谈内容附件<i class="fa fa-asterisk txt-color-red"></i></label>
        <div class="col-md-6">
          <input name="uploadify" id="talkFileName" placeholder="" type="file" style="display: none" >
          <input name="talkFileId" id="talkFileId" style="display: none" value="${talkFileId}">
        </div>
      </div>

      <div class="form-group">
        <label class="col-md-2 control-label">参与人员<i class="fa fa-asterisk txt-color-red"></i></label>
        <div class="col-md-6">
          <input type="text" name="joinMember" id="joinMember" class="form-control" placeholder="请输入参与人员" value="${businessTalk.joinMember}">
        </div>
      </div>

      <div class="form-group">
        <label class="col-md-2 control-label">提交人</label>
        <div class="col-md-2">
          <p class="form-control-static">${businessTalk.creater.name}</p>
        </div>
        <label class="col-md-2 control-label">提交日期</label>
        <div class="col-md-2">
          <p class="form-control-static"><fmt:formatDate pattern="yyyy-MM-dd" value="${businessTalk.createTime}" /></p>
        </div>
      </div>

      <c:if test='${(businessTalk.processState=="Running" || businessTalk.processState=="Backed") && stepNo !=1 && stepNo !=0}'>
        <div class="form-group" id="comment">
          <label class="col-md-2 control-label">审批意见</label>
          <div class="col-md-6">
            <textarea name="editor" id="editor" style="height:200px;"></textarea>
          </div>
        </div>
      </c:if>
    </form>

    <div class="flow">
      <div class="panel-footer">
        <a class="btn btn-default" id="apply-re-common" href="javascript:void(0)">
          <i class="fa fa-lg fa-mail-reply"></i> 返回
        </a>
        <a class="btn btn-default"  key="ajax_edit" href="javascript:void(0);" ${isEdit}>
          <i class="fa fa-lg fa-edit"></i> 编辑
        </a>

      </div>
      <div class="f_title"><i class="right" id="flow1"></i>流程信息</div>
      <div class="f_content" style="display:none">
        <div id="showFlow1"></div>
      </div>
      <div class="f_title"><i class="right" id="next1"></i>下一步骤提示</div>
      <div class="f_content" style="display:none">
        <div id="showNext1"></div>
      </div>
    </div>
  </div>
</div>


<script>
  var index = "${index}";
  var todo = "${todo}";
  var remind = "${remind}";
  var record = "${record}";
  var draft =  "${draft}";
  var stepNo = "${stepNo}";

  $(function(){

    $("#form_businessTalk_input input").attr("disabled",true);

    loadURL("<%=path%>/com/running/workflow?bussinessId="+$("#form_businessTalk_input #keyId").val()+"&type=flow",$('#showFlow1'));
    loadURL("<%=path%>/com/running/workflow?bussinessId="+$("#form_businessTalk_input #keyId").val()+"&type=next",$('#showNext1'));
    __ajax_post("<%=path%>/com/running/operateType",{keyId: $("#form_businessTalk_input #keyId").val()},function(pdata){
      var showDuty = false;
      var area = $("div.panel-footer");
      var edit = null;
      if (stepNo == 1){
        return false;
      }
      $(pdata.datarows).each(function(i,v){
        var str = '<a id="left_foot_btn_'+ v.action+'" class="btn btn-warning" href="javascript:void(0);"><i class="fa fa-upload">'+ v.name+'</i></a>&nbsp;';
        $(area).append(str);
        if(v.action == "approve" || v.action=="sendback"  || v.action=="deny"){
          showDuty = true;
        }
      });
      if(showDuty == true){
        var pdata = {
          keyId: $("#form_businessTalk_input #keyId").val(),
          entityName: "com.fz.us.oa.core.entity.com.BusinessTalk"
        };
        multiDuty(pdata);
      }else{
        $('#comment').hide();
      }
      if($(':visible#editor').length == 1){
        edit  = new UE.ui.Editor();
        edit.render('editor');
      }
      //通过
      $("#left_foot_btn_approve").off("click").on("click",function(){
        var comment = "";
        if(edit != null){
          comment = encodeURIComponent(edit.getContent());
        }
        if($.trim(comment) == ""){
          alert("请填写审批意见");
          return false;
        }
        var stepNo = "${stepNo}";
        if(stepNo == "3"){
          var rs =  $("#form_businessTalk_input").valid();
          if(!rs){
            return false;
          }
        }
        __form_save("form_businessTalk_input","<%=path%>/com/businessTalk/approve?comment="+comment,function(){
          $("#apply-re-common").trigger("click");
        })
      });
      //退回
      $("#left_foot_btn_sendback").off("click").on("click",function(){
        var comment = "";
        if(edit != null){
          comment = encodeURIComponent(edit.getContent());
        }
        if($.trim(comment) == ""){
          alert("请填写审批意见");
          return false;
        }
        var vActionUrl="<%=path%>/com/businessTalk/back?comment="+comment+"&curDutyId="+$('#curDutyId').val();
        var data={keyId:$("input#keyId").val()};
        __ajax_post(vActionUrl,data,function(pdata){
          __toastr(pdata);
          $("#apply-re-common").trigger("click");
        });
      });
      //否决
      $("#left_foot_btn_deny").off("click").on("click",function(){
        var comment = "";
        if(edit != null){
          comment = encodeURIComponent(edit.getContent());
        }
        if($.trim(comment) == ""){
          alert("请填写审批意见");
          return false;
        }
        var vActionUrl="<%=path%>/com/businessTalk/deny?comment="+comment+"&curDutyId="+$('#curDutyId').val();
        var data={keyId:$("input#keyId").val()};
        __ajax_post(vActionUrl,data,function(pdata){
          __toastr(pdata);
          $("#apply-re-common").trigger("click");
        });
      });
    });

    //流程信息展开
    $('#flow1,#next1').click(function(){
      if($(this).hasClass("right")){
        $(this).removeClass("right").addClass("down");
        $(this).parent(".f_title").next("div.f_content").show();
      }else{
        $(this).removeClass("down").addClass("right");
        $(this).parent(".f_title").next("div.f_content").hide();
      }
    });
  });

  readLoad({
    objId:"talkFileName",
    entityName:"talkFileIds",
    sourceId:"talkFileId"
  });

  //返回视图
  $("#apply-re-common").click(function(){
    if(index==1){
      loadURL("menu/dashboard",$('#page-content'));
    }else if(todo==1){
      loadURL("menu/toDo",$('#page-content'));
    }else if(remind==1){
      loadURL("menu/remind",$('#page-content'));
    }else if(record==1){
      loadURL("menu/taskRecord?type=1",$('#page-content'));
    }else if(record==2){
      loadURL("menu/taskRecord?type=2",$('#page-content'));
    }else if(draft==1){
      loadURL("menu/draft",$('#page-content'));
    }else{
      returnToHashUrl()
    }
  });

  //编辑
  $("a[key=ajax_edit]").click(function(){
    loadURL("<%=path%>/com/businessTalk/input?keyId="+$("input#keyId").val()+"&draft="+draft+"&todo="+todo+"&remind="+remind+"&record="+record+"&index="+index,$('#page-content'));
  });

</script>